
package controller;

import java.io.*;
import java.util.List;
import java.util.LinkedList;


import common.Match;
import interfaces.ITransaction;
import interfaces.IStreamProcessor;
import hash.SimpleProcessor;
import java.util.Iterator;

public class Entry {

    public static void main(String[] args) {
        int windowSize = 1024;
        int paneSize = 128;
        double support = 0.10;
        
        try{
            long startTime = System.currentTimeMillis();
            long passedTime;
                
            PrintWriter log = new PrintWriter( new FileOutputStream(new File("log.log"),false));
            PrintWriter output = new PrintWriter( new FileOutputStream(new File("out.csv"),false));
                   
            List<ITransaction> transactions = (new FileProcessorInteger()).getTransactions("kosarak10000.dat");
             
            List<List<Match>> matches = new LinkedList<List<Match>>();
            
            IStreamProcessor processor = new SimpleProcessor();
            processor.setWindow(windowSize, paneSize);
            processor.setSupport(support);
            processor.init();
            
            List<Match> match = new LinkedList<Match>();
            
            
            passedTime = System.currentTimeMillis()-startTime;
            log.println("Beginning at:\n"+Long.toString(passedTime));
            for (int i=0; i<transactions.size(); ++i){
                log.println( ((SimpleProcessor)processor).table.table.size()  );
                match = processor.addTransaction( transactions.get(i) );
                if (match!=null)
                    matches.add(match);
            }
            passedTime = System.currentTimeMillis()-startTime;
            log.println("Finished processing at:\n"+Long.toString(passedTime));
            
            (new ResultPrinter(output,windowSize, paneSize)).print(matches);
         
            log.close();
            output.close();
        }
        catch(Exception ex){
            ex.printStackTrace();
        }
    }
}
